var api = require("../../../../source/js/service.js");
avalon.component('ms-noticeTypes',{
	template:require('./noticeTypes.html'),
	defaults:{
		noticeTypes:[],
		currType:'',
		allType:{
			id:'',
			name:'全部'
		},
		changeType:function(id){
			this.currType = id
			var that = this
			avalon.log('before click')
			var setNameActionCreator = function(name){
				return {
					type:'SET_NAME',
					name:name,
					setting:that.currType
				}
			}
			window.duxStore.dispatch(setNameActionCreator('changeNoticesType'))
			avalon.log('clicked')
		},
		getNoticeTypes:function(){
			var that = this
			return api.getItems({
				method:api.getNoticeTypes,
				query:{}
			},function(res){
				if(res.success){
					that.noticeTypes.clear()
					that.noticeTypes.push(that.allType)
					that.noticeTypes.pushArray(res.data.list)				}
			})
		},
		onInit:function(){
			var that = this
			var setNameActionCreator = function(name){
				return {
					type:'SET_NAME',
					name:name,
					setting:that.currType
				}
			}
			window.duxStore.dispatch(setNameActionCreator('changeNoticesType'))
			this.getNoticeTypes()
		},
		onReady:function(){
			

		}
	}
})